import urllib2,sys
import urllib,sys

def scrape(mode, search, format):

	#build URI
	if(mode=="mas"):
		url="http://academic.research.microsoft.com/"+str(search)+".txt?type=10&entitytype=2&format=0&download=0"
		
		#get and return resource
		return urllib2.urlopen(url).read()
		
	if(mode=="gcit"):
		url="http://scholar.google.com/citations?view_op=export_citations&hl=en&user="+str(search)
		user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
		header = { 'User-Agent' : user_agent }

		values = {
		  'cit_fmt' : 0
		}

		data = urllib.urlencode(values)
		# req = urllib2.Request(url+data, None, header) # GET works fine
		req = urllib2.Request(url, data, header)  # POST request doesn't not work

		return urllib2.urlopen(req).read()
		

	
